﻿using CefSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chen.CefWebKit.Handler
{
    public class CookieUserVisitor : ICookieVisitor
    {
        System.Net.CookieContainer cookies = new System.Net.CookieContainer();
        public void Dispose()
        {
            
        }

        public bool Visit(Cookie cookie, int count, int total, ref bool deleteCookie)
        {
            cookies.Add(new System.Net.Cookie() {
                Name =cookie.Name,
                Value=cookie.Value.Replace(",", "%2c"),
                Domain=cookie.Domain,
                Path=cookie.Path,
                Secure=cookie.Secure,
                HttpOnly=cookie.HttpOnly,
                Expires=cookie.Expires==null?cookie.Creation.AddDays(1):cookie.Expires.Value
            });
            return true;
        }

        public System.Net.CookieContainer GetContainer()
        {
            return cookies;
        }
    }
}
